package com.example.javaeefinal.utils;

import lombok.Data;

/**
 * @Auther: Lai Wenhao
 * @Date: 2023/12/27 16:11
 **/
@Data
public class Result<T> {
private String code;
private String message;
private T data;
    public Result() {
    }

    public Result(T data) {
        this.data = data;
    }

    public static Result success() {
        Result result = new Result<>();
        result.setCode("0");
        result.setMessage("成功");
        return result;
    }

    public static <T> Result<T> success(T data) {
        Result<T> result = new Result<>(data);
        result.setCode("0");
        result.setMessage("成功");
        return result;
    }

    public static <T> Result<T> success(T data,String msg) {
        Result<T> result = new Result<>(data);
        result.setCode("0");
        result.setMessage(msg);
        return result;
    }

    public static <T> Result<T> success(String code, T data,String msg) {
        Result<T> result = new Result<>(data);
        result.setCode(code);
        result.setMessage(msg);
        return result;
    }

    public static <T> Result<T> success(String code, T data) {
        Result<T> result = new Result<>(data);
        result.setCode(code);
        return result;
    }

    public static <T> Result<T> success(String code, String msg) {
        Result<T> result = new Result<>();
        result.setMessage(msg);
        result.setCode(code);
        return result;
    }

    public static Result error(String code, String msg) {
        Result result = new Result();
        result.setCode(code);
        result.setMessage(msg);
        return result;
    }
}
